package com.nulldev.util.web.HttpServer3.extensions.sse;

import java.util.Map;
import java.util.UUID;
import java.util.stream.Stream;

import com.nulldev.util.data.Arrays.maps.trie.TrieMap;

public class SSESessionManager {
	private final Map<UUID, SSESession> session = new TrieMap<UUID, SSESession>();

	public SSESessionManager() {
	}

	public boolean sessionExists(final UUID uuid) {
		return this.session.containsKey(uuid);
	}

	public SSESession session(final UUID uuid) {
		return this.session.get(uuid);
	}

	public void registerSession(final SSESession peer) {
		this.session.put(peer.getUUID(), peer);
	}

	public void removeSession(SSESession peer) {
		this.session.remove(peer.getUUID());
	}

	public Stream<SSESession> clients() {
		return this.session.values().parallelStream();
	}
}
